package net.yunxinyong.cec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.yunxinyong.cec.entity.Cec711FiveFinanceWages;
import net.yunxinyong.cec.entity.Cec711FiveFinanceWagesExample;
import net.yunxinyong.cec.mapper.Cec711FiveFinanceWagesMapper;
import net.yunxinyong.cec.service.Cec711FiveFinanceService;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李跃
 * @date
 */
@Service
public class Cec711FiveFinanceServiceImpl implements Cec711FiveFinanceService {
    @Autowired
    private Cec711FiveFinanceWagesMapper cec711FiveFinanceWagesMapper;

    @Override
    public Cec711FiveFinanceWages insertFive(Cec711FiveFinanceWages cec711FiveFinanceWages) {
        //根据base_id判断信息是否重复
        Cec711FiveFinanceWagesExample cec711FiveFinanceWagesExample = new Cec711FiveFinanceWagesExample();
        cec711FiveFinanceWagesExample.createCriteria().andBaseIdEqualTo(cec711FiveFinanceWages.getBaseId());
        List<Cec711FiveFinanceWages> cec711FiveFinanceWagesList = cec711FiveFinanceWagesMapper.selectByExample(cec711FiveFinanceWagesExample);
        if(!cec711FiveFinanceWagesList.isEmpty()){
            return null;

        }
        int i = cec711FiveFinanceWagesMapper.insertSelective(cec711FiveFinanceWages);
        return cec711FiveFinanceWages;
    }

    @Override
    public int deleteFive(Integer id) {
        //根据base_id更改状态
        Cec711FiveFinanceWages cec711FiveFinanceWages = new Cec711FiveFinanceWages();
        cec711FiveFinanceWages.setBaseId(id);
        cec711FiveFinanceWages.setStatus(0);
        return cec711FiveFinanceWagesMapper.updateByPrimaryKeySelective(cec711FiveFinanceWages);
    }

    @Override
    public int updateFive(Cec711FiveFinanceWages Cec711FiveFinanceWages) {
        int i = cec711FiveFinanceWagesMapper.updateByPrimaryKeySelective(Cec711FiveFinanceWages);
        return i;
    }

    @Override
    public PageBean ListFvieByname(Cec711FiveFinanceWages Cec711FiveFinanceWages, int page, int rows) {
        if(page!=0 && rows !=0){
            PageHelper.startPage(page,rows);
        }
        Cec711FiveFinanceWagesExample cec711FiveFinanceWagesExample = new Cec711FiveFinanceWagesExample();
        Cec711FiveFinanceWagesExample.Criteria criteria = cec711FiveFinanceWagesExample.createCriteria();
        criteria.andBaseIdEqualTo(Cec711FiveFinanceWages.getBaseId());
        List<Cec711FiveFinanceWages> cec711FiveFinanceWagesList = cec711FiveFinanceWagesMapper.selectByExample(cec711FiveFinanceWagesExample);
        PageBean<Cec711FiveFinanceWages> pageBean = new PageBean<>();
        PageInfo<Cec711FiveFinanceWages> pageInfo = new PageInfo<>(cec711FiveFinanceWagesList);
        pageBean.setTotal(pageInfo.getTotal());
        pageBean.setTotalPages(pageInfo.getPages());
        pageBean.setPageDatas(cec711FiveFinanceWagesList);
        return pageBean;
    }


}
